package com.yxj.dries.data;

import android.app.Application;
import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverter;
import androidx.room.TypeConverters;

import com.yxj.dries.lib.global.AppGlobals;
import com.yxj.dries.model.User;

@Database(entities = {User.class}, version = 1)
@TypeConverters(Converters.class)
public abstract class AppDataBase extends RoomDatabase {

    private static AppDataBase database;

//    static {
//        database = Room.databaseBuilder(AppGlobals.getApplication().getApplicationContext(), AppDataBase.class, "yxj")
//                //是否允许在主线程进行查询
//                .allowMainThreadQueries()
//                .build();
//    }


    public abstract UserDao userDao();

    public synchronized static AppDataBase get(Context context) {

        database = Room.databaseBuilder(context, AppDataBase.class, "yxj")
                //是否允许在主线程进行查询
                .allowMainThreadQueries()
                .build();

        return database;
    }

}
